<?php
namespace app\api\validate;

class Account extends \think\Validate
{
    protected $rule =   [
        'username|用户名'  => ['require', 'regex'=>'/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/'],
        'nickname|昵称'   => 'min:2|max:55',
        'password|密码' => 'require|min:6|max:20',
        'action|操作' => 'require|eq:code',// 通过手机验证码登录时需要的；
        'code|验证码' => 'require|length:6',// 通过手机验证码登录时需要的；

        // 注册时手机、邮箱等都是非必须的，但绑定（修改）时是必须的；
        // 规则无法集中在一起，所以选择绑定的验证在控制器中额外处理。
        'mobile|手机号码' => ['regex'=>'/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/'],
        'email|电子邮箱' => 'require|email',
        'address|联系地址' => 'require|min:2|max:255',
        'account_id|账户ID' => 'require|number|egt:1'
    ];
    
    protected $scene = [
        // 'register'  =>  ['username', 'nickname', 'password'],
        'loginPasswordRequired'  =>  ['username', 'password'],
        'loginCodeRequired'  =>  ['username', 'code', 'action'],
        
        'mobile'  =>  ['mobile'],
        'email'  =>  ['email'],
        'address'  =>  ['address'],
        'account_id'  =>  ['account_id']
    ];
    
}